package com.huxiu.holder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huxiu.HuaTiDetailActivity;
import com.huxiu.R;
import com.huxiu.net.model.GroupInfo;
import com.huxiu.utils.Constants;
import com.huxiu.utils.ImageLoaderOptions;
import com.huxiu.utils.UmenEvent;
import com.huxiu.utils.Utils;
import com.huxiu.view.RoundImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;

import java.lang.ref.WeakReference;


public class GroupInfoHolder implements OnClickListener {

    @ViewInject(R.id.text_title)
    private TextView text_title;

    @ViewInject(R.id.avatar)
    private RoundImageView avatar;

    @ViewInject(R.id.container)
    private LinearLayout container;

    @ViewInject(R.id.text_name)
    private TextView text_name;

    @ViewInject(R.id.text_looknum)
    private TextView text_looknum;


    @ViewInject(R.id.time)
    private TextView time;


    private static Activity mContext;
    private static WeakReference<BaseAdapter> mAdapter;

    public void setAdapter(BaseAdapter adapter) {
        mAdapter = new WeakReference<>(adapter);
    }

    public GroupInfoHolder(View view, Context context) {
        ViewUtils.inject(this, view);
        mContext = (Activity) context;
        container.setOnClickListener(this);
    }


    //    private boolean isMine2 = false;

    private GroupInfo.Thread mItem;

    public void bindItem(GroupInfo.Thread item) {
        mItem = item;
        text_title.setText(mItem.title);
        text_name.setText(mItem.userinfo.username);
        text_looknum.setText(Utils.getSeeNumToStr(Integer.parseInt(mItem.view_num))+"人浏览");
        time.setText(Utils.getDateString(mItem.time));
        ImageLoader.getInstance().displayImage(
                mItem.userinfo.avatar+Constants.IMAGE_WEBP, avatar, ImageLoaderOptions.options);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.container:
                UmenEvent.UmengEventMap(mContext, UmenEvent.APP_TOPIC_LIST, UmenEvent.TOPIC_LIST_TOPIC);
                Intent intent = new Intent(mContext, HuaTiDetailActivity.class);
                intent.putExtra(Constants.GROUP_HUATI_ITEM_ID, mItem.id);
                mContext.startActivity(intent);
                break;
        }
    }

}
